<?php
include '../../common.inc.php';
error_reporting(-1);
$hd = new ImportLoop();
$hd->setAim('mysql:host=192.168.1.19;dbname=caiji', 'root', 'xddlxdcw');
$hd->setSource('mysql:host=192.168.1.19;dbname=ixdcw_v11', 'root', 'xddlxdcw');
$hd->setSourceInfo('xd_auto_model', 'amid', '');
$params = array(
	'maxid'     => isset($_GET['maxid']) ? $_GET['maxid'] : 0,
	'id'        => isset($_GET['id']) && !empty($_GET['id']) ? $_GET['id'] : 19452,
	'startTime' => isset($_GET['startTime']) ? $_GET['startTime'] : time(),
	'limit'     => 20,
	'interval'  => 1,
	'debug'     => isset($_GET['debug']) ? $_GET['debug'] : 'xddl',
);
$hd->initParams($params);
$sql = 'select * from ' . $hd->getSourceTable() . ' where amid>' . $hd->getParam('id') . ' order by amid ASC limit ' . $hd->getParam('limit');
$result = $hd->getDbSource()->query($sql);
$rs     = $result->fetchAll();

if (!$rs) {
	$hd->end();
} else {
	$modelFolders = array();
	foreach ($rs as $k => $v) {
		$modelFolders[]    = array(
			str_replace('E:/Folder', '', AutoImport::modelFolder($v['amid'])),
			$v['arbid'], $v['arcid'], $v['amid']
		);
		$hd->setParam('id', $v['amid']);
	}
	$sql = "insert autohome_importpicture (folder, arbid, arcid, amid) values";
	$values = array();
	foreach($modelFolders as $k => $va) {
		$values[] = '(\''.implode('\',\'', $va).'\')';
	}

	$sql .= implode(',', $values);

	if ($hd->getDbAim()->query($sql)) {
		var_dump($v['amid'], $v['name'], $hd->times(), $hd->getParam('maxid'));
	} else {
		print_r($sql);
		exit();
	}
}
var_dump($hd->getParams());
echo $hd->start($hd->getParams());